<?php
/**
 * Created by PhpStorm.
 * User: 悟能科技
 * Date: 2018/8/30
 * Time: 19:40
 */

namespace app\mos\controller;


use think\Controller;

class Qrcodes extends Controller
{

    //开卡组件二维码
    public function cardbizqrcode($id,$url = 'https://os.wunengkeji.com', $level = 4, $size = 16){
//        return $id;
        $qrCode = new \Endroid\QrCode\QrCode();
        $qrCode->setText($url)
            ->setSize(570)//大小
            //->setLabelFontPath(VENDOR_PATH . 'endroid/qrcode/assets/noto_sans.otf')
            ->setErrorCorrectionLevel('high')
            ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
            ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));

        header('Content-Type: ' . $qrCode->getContentType());
        $image = $qrCode->writeString();
        $path = $_SERVER['DOCUMENT_ROOT'] . "/mobile/share/" . $id . '.png';
        file_put_contents($path, $image);
//        $res =  request()->domain() .  "/biz/card/" . $id . '.png';
        return $path;
    }
}